console.log(1)
const url = 'https://movie.douban.com/explore#!type=movie&tag=%E6%9C%80%E6%96%B0&page_limit=20&page_start=0';
const puppeteer = require('puppeteer');
console.log(2)
const sleep = time => new Promise(resolve => {
    setTimeout(resolve, time);
});

;(async () => {
    console.log('Start visit the target page');
    const browser = await puppeteer.launch({
        args:['--no-sandbox'],
        dumpio:false
    })
    const page = await browser.newPage()
    await page.goto(url,{
        waitUntil: 'networkidle2'
    })
    await sleep(3000)
    await page.waitForSelector('.more')
    for (let i=0;i<1;i++){
        await sleep(3000)
        await page.click('.more')
    }
    const result = await page.evaluate(() => {
        var $ = window.$;
        var items = $('.list-wp a');
        var links = [];
        if(items.length > 1){
            items.each((index,item) => {
                let it = $(item);
                console.log(it);
                let doubanId = it.find('div').data('id');
                let title = it.find('p').html();

                let rate = Number(it.find('strong').text());
                let poster = it.find('.cover-wp img').attr('src');
                console.log(poster)
                poster = typeof poster !== 'string'
                    ? poster
                    : poster.replace('s_ratio','l_ratio');

                links.push({
                    doubanId,
                    title,
                    rate,
                    poster
                })
            })
        }

        return links;
    })

    browser.close();
    console.log(result)
})()